<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class RoomsResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        return [
            'id'=>$this->id,
            'sid'=>(int)$this->sid,
            'name'=>$this->name,
            'description'=>$this->description,
            'status'=>(int)$this->status,
            'lbt_img'=>$this->when(!empty($this->lbt_img),function (){
                $imgs=json_decode($this->lbt_img,true);
                foreach ($imgs as $imgkey=>$img){
                    $imgs[$imgkey]=env('APP_URL').'/uploads/'.$img;
                }
                return $imgs;
            }),
            'created_at'=>(string)$this->created_at,
            'updated_at'=>(string)$this->updated_at,
        ];
    }
}
